package com.itheima.job5;

import java.io.*;

public class test {
    public static void main(String[] args) {
        FileInputStream fis=null;
        FileOutputStream fos=null;
        try {
            File infile = new File("E:\\javasepro\\day10-IO流（二）\\IO资源路径");
            File outfile = new File("E:/test/");
            int read;
            byte[] buffer = new byte[1024];
            File[] files = infile.listFiles(s -> s.getName().split("\\.")[1].equals("jpeg"));
            for (File file : files) {
                System.out.println(file.getName());
            }
            for (int i = 0; i < files.length; i++) {
                FileOutputStream fileOutputStream=new FileOutputStream(outfile.getAbsolutePath().replaceAll("\\\\","/") + "/"+files[i].getName());;
                FileInputStream fileInputStream =new FileInputStream(files[i]);
                while((read=fileInputStream.read(buffer))!=-1){
                    fileOutputStream.write(buffer,0,read);
                }
                fileOutputStream.close();
                fileInputStream.close();

            }
        } catch (IOException e) {
          e.printStackTrace();
        }

    }
}
